import { useFormatterEmpNameAndId } from '/@/hooks/formatter'
import { useTableColumnProps } from '/@/hooks/table-column/props'

/**
 * 显示员工名字和员工号
 * @param label column.label
 * @param propName 名字字段名
 * @param propId ID字段名
 * @param options tableColumn的其他属性
 * @returns tableColumn props
 */
export function useTableColumnEmpNameAndId<
  T extends Record<string, any>,
  P extends keyof T
>(
  label = '姓名（员工号）',
  propName: P = 'empName' as P,
  propId: P = 'empNo' as P,
  options: UseTableColumnProps<any, T, P> = {}
) {
  return useTableColumnProps<T, P>(propName, label, {
    width: 145,
    formatter: row => useFormatterEmpNameAndId<T>(row, propName, propId),
    ...options
  })
}

/**
 * 显示多个员工名字和员工号
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @param propName 名字字段名, 默认 empName
 * @param propId ID字段名, 默认 empNo
 * @returns tableColumn props
 */
export function useTableColumnEmpNameAndIds<
  T extends Record<string, any>,
  P extends keyof T
>(
  prop: P,
  label: string,
  options: UseTableColumnProps<any, T, P> = {},
  propName: keyof T = 'empName',
  propId: keyof T = 'empNo'
) {
  return useTableColumnProps(prop, label, {
    width: 200,
    formatter: (row: T) =>
      row[prop]
        ?.map((item: T) => useFormatterEmpNameAndId<T>(item, propName, propId))
        .join('，'),

    ...options
  })
}
